public class Solution1640 {
    public boolean canFormArray(int[] arr, int[][] pieces) {
        int now=0;
        while (now<arr.length){
            boolean flag=false;
            for (int[] piece : pieces) {
                if (piece[0]==arr[now]){
                    int t=0;
                    while (t<piece.length && piece[t]==arr[now+t]){
                        t++;
                    }
                    if (t==piece.length){
                        now+=t;
                        flag=true;
                        break;
                    }else {
                        return false;
                    }
                }
            }
            if (!flag){
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1640().canFormArray(new int[]{15,88},new int[][]{{88},{15}}));
    }
}
